﻿using SvgViewer.Core;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;

namespace SvgViewer.ViewModel
{
    /// <summary>
    /// 关于视图 ViewModel
    /// </summary>
    public class AboutViewModel : ViewModelBase
    {
        /// <summary>
        /// 构造
        /// </summary>
        public AboutViewModel()
        {
            OpenLinkCommand = new RelayCommand(OpenLink);

            var assembly = Assembly.GetAssembly(this.GetType());
            Version = $"{assembly.GetName().Version}";

            foreach (var attribute in assembly.GetCustomAttributes(true))
            {
                var attType = attribute.GetType();
                if (attType == typeof(AssemblyCopyrightAttribute))
                {
                    Copyright = ((AssemblyCopyrightAttribute)attribute).Copyright;
                    break;
                }
            }

            BuildTime = File.GetCreationTime(assembly.Location).
                ToString(System.Globalization.CultureInfo.CurrentCulture);

            Thanks = new ObservableCollection<Tuple<string, string>> {
                new("Material Design In XAML Toolkit", "https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit"),
                new("SharpVectors.Wpf", "https://github.com/ElinamLLC/SharpVectors"),
                new("SvgToXaml", "https://github.com/BerndK/SvgToXaml")
            };
        }

        /// <summary>
        /// 鸣谢列表
        /// </summary>
        public ObservableCollection<Tuple<string, string>> Thanks
        {
            get;
        }

        /// <summary>
        /// 版本
        /// </summary>
        public string Version {
            get;
        }

        /// <summary>
        /// 生成时间
        /// </summary>
        public string BuildTime {
            get;
        }

        /// <summary>
        /// 版权
        /// </summary>
        public string Copyright {
            get;
        }

        /// <summary>
        /// 打开鸣谢链接命令
        /// </summary>
        public RelayCommand OpenLinkCommand {
            get;
        }

        private void OpenLink(object uri)
        {
            Process.Start($"{uri}");
        }
    }
}